/**上午10:29:57
 * @author zhangyh2
 * OrnamentalFlowerFragment.java
 * TODO
 */
package cn.com.darly.videoandroidpm.ui.fragment;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.darly.dview.common.SCfg;
import com.darly.dview.widget.camera.util.ImageLoaderUtil;

import cn.com.darly.videoandroidpm.R;
import cn.com.darly.videoandroidpm.base.BaseFragment;
import cn.com.darly.videoandroidpm.bean.LoginInfo;
import cn.com.darly.videoandroidpm.common.SharePreferHelp;
import cn.com.darly.videoandroidpm.common.SystemLoginInfo;
import cn.com.darly.videoandroidpm.ui.PMActivity;
import cn.com.darly.videoandroidpm.widget.dialog.ImageLoadingDialog;

/**
 * 用戶信息界面
 * Copyright (c) 2017 Organization D.L. zhangyuhui All rights reserved.
 * @author  Darly/张宇辉/2018/5/4 11:35
 * @version  1.0/cn.com.darly.videoandroidpm.ui.fragment
 */

public class CenterFragment extends BaseFragment implements OnClickListener {


	private TextView id_user_info_account;
	private TextView id_user_info_realname;
	private TextView id_user_info_phone;
	private ImageView id_user_info_icon;
	private ImageView id_user_info_image;
	private Button id_fragment_main_loginout;

	ImageLoadingDialog dialog;

	@Override
	protected int root() {
		return R.layout.fragment_main_center;
	}

	@Override
	protected void initView(Bundle savedInstanceState) {
		id_user_info_account = rootView.findViewById(R.id.id_user_info_account);
		id_user_info_realname = rootView.findViewById(R.id.id_user_info_realname);
		id_user_info_phone = rootView.findViewById(R.id.id_user_info_phone);
		id_user_info_icon = rootView.findViewById(R.id.id_user_info_icon);
		id_user_info_image = rootView.findViewById(R.id.id_user_info_image);
		id_fragment_main_loginout = rootView.findViewById(R.id.id_fragment_main_loginout);

		id_user_info_icon.setLayoutParams(new LinearLayout.LayoutParams(SCfg.getWidth() / 5, SCfg.getWidth() / 5));

		dialog = new ImageLoadingDialog(getActivity());
		dialog.setContentView(R.layout.dialog_image);
		dialog.setCanceledOnTouchOutside(true);
		initFragments(null,SettingFragment.class, R.id.id_user_info_frame);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.hellen.base.BaseFragment#loadData()
	 */
	@Override
	protected void loadData() {
		LoginInfo info = (LoginInfo) SharePreferHelp.getValue("LoginInfo");
		if (!TextUtils.isEmpty(info.getIcon())) {
			ImageLoaderUtil.getInstance().loadImage(info.getIcon(), id_user_info_icon);
		} else {
			id_user_info_icon.setImageResource(R.mipmap.ic_setting_user_icon);
		}
		id_user_info_account.setText(String.format("账户："+ info.getAccount()));
		id_user_info_realname.setText(String.format("昵称：" + info.getName()));
		id_user_info_phone.setText(String.format("手机："+ info.getMobile()));
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.hellen.base.BaseFragment#initListener()
	 */
	@Override
	protected void initListener() {
		id_user_info_image.setOnClickListener(this);
		id_user_info_icon.setOnClickListener(this);
		id_fragment_main_loginout.setOnClickListener(this);
	}


	@Override
	public void onClick(View v) {
		switch (v.getId()){
			case R.id.id_user_info_image:
				//点击后面二维码图片
				dialog.setImageResouce(R.mipmap.ic_setting_imager);
				dialog.show();
				break;
			case R.id.id_user_info_icon:
				//点击前面用户图像
				dialog.setImageResouce(R.mipmap.ic_setting_user_icon);
				dialog.show();
				break;
			case R.id.id_fragment_main_loginout:
				SystemLoginInfo.loginout();
				SharePreferHelp.remove("LoginInfo");
				((PMActivity)getActivity()).swichTo(R.id.id_main_footer_main);
				break;
		}
	}
}
